package xyz.xxpc.springcloud.consumer.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import xyz.xxpc.springcloud.consumer.service.UserService;
import xyz.xxpc.springcloud.pojo.User;
import xyz.xxpc.springcloud.service.api.UserService20081;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    // 如果使用服务器提供者?
    // 如果使用 具体的地址 还有负载均衡效果
    // 使用了负载均衡也就不需要再写明确的地址了
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    private UserService20081 userService20081;

    @Autowired
    public void setUserService20081(UserService20081 userService20081) {
        this.userService20081 = userService20081;
    }

    @GetMapping("/30081")
    public List<User> query30081All(){
        return  userService20081.queryAll();
    }
    @GetMapping("/all")
    public List<User> queryAll(){
        return  userService.queryAll();
    }
    @GetMapping("/{id}")
    public User query(@PathVariable("id") Integer id){
        return  userService.query(id);
    }

    @PostMapping("/add")
    public User add(@RequestBody User user){
        return  userService.add(user);
    }
}
